home *** CD-ROM | disk | FTP | other *** search
- /* fdopen.c */
- #include <stdio.h>
- #include <io.h>
- #include <fcntl.h>
- main()
- {
- int handle;
- FILE *infile;
- char buffer[80];
- /* Open the file. Note that we need two '\' */
- if ((handle = open("c:\\autoexec.bat", O_RDONLY)) == -1)
- {
- perror ("opened failed");
- exit(1);
- }
- /* Use fdopen to assign a FILE data structure to file */
- if ((infile = fdopen(handle, "r")) == NULL)
- {
- perror("fdopen failed");
- exit(1);
- }
-
- /* All's well. Read and print the contents of the file */
- printf("Contents of c:\autoexec.bat:\n");
- while (fgets(buffer, 80, infile) != NULL)
- {
- printf(buffer);
- }
- }